package quick.frame.core.util.file;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import java.sql.Connection;

public class SpUtil {
	private static final String NAME="HWMS";
	private static SpUtil instance;
	public static final String SERVER_ADDRESS = "SERVER_ADDRESS";
	public static final String SERVER_PORT = "SERVER_PORT";
	public static final String SERVER_NAME = "SERVER_NAME";
	public static final String SERVER_URL = "SERVER_URL";
	public static final String USER_NAME = "USER_NAME";
	public static final String BLUETOOTH_ADDRESS = "BLUETOOTH_ADDRESS";
	public static final String BLUETOOTH_USED = "BLUETOOTH_USED";
	public static Connection BLUETOOTH_CONNECTION = null;
	
	static{
		instance=new SpUtil();
	}
	
	private SpUtil() {
		
	}
	public static SpUtil getInstance(){
		if(instance==null){
			instance=new SpUtil();
		}
		return instance;
	}
	
	public static Connection getConnection(){
		return BLUETOOTH_CONNECTION;
	}
	
	public static void setConnection(Connection connection) {
		BLUETOOTH_CONNECTION = connection;
	}
	
	public static SharedPreferences getSharePerference(Context context){
		return context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
	}
	
	public static boolean isFirst(SharedPreferences sp){
		return sp.getBoolean("isFirst", true);
	}
	
	public static void setStringSharedPerference(SharedPreferences sp, String key, String value){
		Editor editor=sp.edit();
		editor.putString(key, value);
		editor.commit();
	}
	
	public static void setBooleanSharedPerference(SharedPreferences sp, String key, boolean value){
		Editor editor=sp.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}
}
